<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.javapig.util.*,com.dd.*,java.util.*"%>
<%@ include file="global.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>

<%
	//厂商数
	int i_factorys = ParamUtils
			.getIntParameter(request, "factorys", -1);
	//商品数
	int i_products = ParamUtils
			.getIntParameter(request, "products", -1);
	//静态区数组
	String[][] static_values = new String[i_products][4];
	//历史价格
	String[] ls = new String[i_products];
	//厂商名称数组
	String[] factoryNames = new String[i_factorys];
	//厂商和产品报价数组
	float[][] prod_comp_bj = new float[i_products][i_factorys];
	//厂商和产品审核价数组
	float[][] prod_comp_sj = new float[i_products][i_factorys];
	//报价总价
	String[] zj_bj = new String[i_factorys];
	//审核价总价
	String[] zj_sj = new String[i_factorys];
	//联系人
	String[] lx = new String[i_factorys];

	System.out.println("i 静态区");
	for (int i = 0; i < i_products; i++) {
		for (int j = 0; j < 4; j++) {
			String id = "i" + (i + 1) + "_" + (j + 1);
			static_values[i][j] = ParamUtils.getParameter(request, id);
			System.out.println(id + "=" + static_values[i][j]);
		}
	}
	
	System.out.println("ls 历史价格");
	for (int i = 0; i < i_products; i++) {
		String id = "ls_" + (i + 1);
		ls[i] = ParamUtils.getParameter(request, id);
		System.out.println(id + "=" + ls[i]);
	}
	
	System.out.println("cj 厂家名称");
	for (int i = 0; i < i_factorys; i++) {
		String id = "cj_" + (i + 1);
		factoryNames[i] = ParamUtils.getParameter(request, id);
		System.out.println(id + "=" + factoryNames[i]);
	}

	System.out.println("bj 产品和厂商报价区");
	for (int i = 0; i < i_products; i++) {
		for (int j = 0; j < i_factorys; j++) {
			String id_bj = "bj" + (i + 1) + "_" + (j + 1);
			String id_sj = "sj" + (i + 1) + "_" + (j + 1);
			prod_comp_bj[i][j] = new Float( ParamUtils
			.getParameter(request, id_bj) ).floatValue();
			System.out.println(id_bj + "=" + prod_comp_bj[i][j]);
			//prod_comp_sj[i][j] = new Float ( ParamUtils
			//.getParameter(request, id_sj) ).floatValue();
			System.out.println(id_sj + "=" + prod_comp_sj[i][j]);
		}
	}

	System.out.println("zj 厂家报价总价");
	for (int i = 0; i < i_factorys; i++) {
		String id_bj = "bjzj_" + (i + 1);
		String id_sj = "bjsj_" + (i + 1);
		zj_bj[i] = ParamUtils.getParameter(request, id_bj);
		System.out.println(id_bj + "=" + zj_bj[i]);
		zj_sj[i] = ParamUtils.getParameter(request, id_sj);
		System.out.println(id_sj + "=" + zj_sj[i]);
	}

	System.out.println("lx 厂家联系人");
	for (int i = 0; i < i_factorys; i++) {
		String id = "lx_" + (i + 1);
		lx[i] = ParamUtils.getParameter(request, id);
		System.out.println(id + "=" + lx[i]);
	}
	
	//java deal
	//表状态 提交
	String biaoZhuangTai = "0";
	//报表名称
	String mingCheng = ParamUtils.getParameter(request, "mingCheng");
	String danJuBiaoHao = ParamUtils.getParameter(request,
			"danJuBiaoHao");
	// 项目id
	int xiangMuId = ParamUtils
			.getIntParameter(request, "xiangMuId", -1);
	// 表类姓名
	String biaoLeiXingMing = ParamUtils.getParameter(request,
			"biaoLeiXingMing");
	if (biaoLeiXingMing == null)
		biaoLeiXingMing = "";
	// 员工ID
	int yuanGongId = pageUser.getId();
		//ParamUtils.getIntParameter(request, "xiangMuId",	-1);
	// 右边备注
	String youBianBeiZhu = ParamUtils.getParameter(request,
			"YouBianBeiZhu");
	if (youBianBeiZhu == null)
		youBianBeiZhu = "";
	//下面备注
	String xiaMianBeiZhu = ParamUtils.getParameter(request,
			"XiaMianBeiZhu");
	if (xiaMianBeiZhu == null)
		xiaMianBeiZhu = "";
	
	//采购报价
	CaiGouBiaoJia cgbj = new CaiGouBiaoJia(biaoZhuangTai, mingCheng,
			danJuBiaoHao, xiangMuId, biaoLeiXingMing, yuanGongId,
			youBianBeiZhu, xiaMianBeiZhu, "", "", "", "", "");
	
	// 采购公司列表
	ArrayList caiGouGongSis = new ArrayList();
	for (int i=0; i< factoryNames.length; i++){
		Map map = new HashMap();
		map.put("GongSiMingCheng",factoryNames[i]);
		map.put("LianXirenHeFangshi",lx[i]);
		map.put("ZongBaoJia",new Float( zj_bj[i]) );
		caiGouGongSis.add(map);
	}
	cgbj.setCaiGouGongSis(caiGouGongSis);
	
	// 采购商品列表
	ArrayList caiGouShangPings = new ArrayList();
	for (int i=0; i< static_values.length; i++){
		Map map = new HashMap();
		map.put("MingCheng", static_values[i][0]);
		map.put("GuiGe", static_values[i][1]);
		map.put( "ShuLiang",new Float(static_values[i][2]) );
		map.put("DanWei", static_values[i][3]);
		map.put("LiShiJiaGe", new Float( ls[i]) );
		caiGouShangPings.add(map);
	}
	cgbj.setCaiGouShangPings(caiGouShangPings);
	
	//报价
	cgbj.setF_product_baojia(prod_comp_bj); 
System.out.println("执行OK");
	//执行数据库操作
	boolean res = cgbj.InsertCaiGouBiaoJiaDan();
	if (res){
		//response.sendRedirect("comm_user.jsp");
		out.println("<script type=\"text/javascript\"> ");
		out.println("document.all.WebBrowser.ExecWB(45,1)");
		out.println("</script>");
	}
%>